<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <script src="../js/vue.js"></script>
  <style>
    li {
      list-style-type: none;
      cursor: pointer;
    }

    .red {
      color: red;
    }
  </style>
</head>

<body>
  <div id="app">
    <ul>
      <li v-for="(item,index) in movies" :class="{red:index === currentIndex}" @click="clickItem(index)">{{item}}</li>
      <!-- <li v-for="(item,index) in movies" :class="index === currentIndex ? 'red' : ''" @click="clickItem(index)">{{item}}</li> -->
    </ul>
  </div>

  <script>
    var vm = new Vue({
      el: '#app',
      data: {
        movies: ['海贼王', '火影忍者', '进击的巨人', '加勒比海盗', '哈利波特'],
        currentIndex: ''
      },
      methods: {
        clickItem(index) {
          this.currentIndex = index
        }
      }
    });
  </script>
</body>

</html>